/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.controller.teacherReviewGroup;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.StringUtils;
import cn.qidisoft.core.util.moffice.excel.ExpExcelUtil;
import cn.qidisoft.core.web.customargument.bind.annotation.Token;
import cn.qidisoft.edu.hzjt.annotation.SysLogger;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.model.Employee;
import cn.qidisoft.edu.hzjt.model.KtglReviewExpert;
import cn.qidisoft.edu.hzjt.model.KtglReviewGroup;
import cn.qidisoft.edu.hzjt.model.KtglTeacherThesisReview;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.model.zyc.TeacherThesisAtt;
import cn.qidisoft.edu.hzjt.service.ICommonService;
import cn.qidisoft.edu.hzjt.service.IKtglReviewGroupService;
import cn.qidisoft.edu.hzjt.service.zyc.ITeacherThesisAttService;
import cn.qidisoft.edu.hzjt.service.zyc.ITeacherThesisService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import cn.qidisoft.edu.hzjt.vo.TeacherThesis;

/**
 * 
 * @author hxq
 * @version $Id: TeacherReviewGroupController.java, v 0.1 2018年12月11日 上午10:24:57 hxq Exp $
 */
@Controller
@RequestMapping("teacherReviewGroup")
public class TeacherReviewGroupController {
  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private IKtglReviewGroupService ktglReviewGroupService;
  @Autowired
  private ICommonService commonService;
  @Autowired
  ITeacherThesisService teacherThesisService;
  @Autowired
  ITeacherThesisAttService teacherThesisAttService;

  /**
   * 专家组管理
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/index")
  public String index(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "teacherReviewGroup/groupTeacher_list";
  }


  /**
   * 
   * 专家组管理列表
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/reviewTeacherGroupList")
  @ResponseBody
  public ResponseResult reviewTeacherGroupList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, KtglReviewGroup data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage(currentPage, pageSize, request, "groupid", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        PaginationBean<KtglReviewGroup> paginationBean =
            ktglReviewGroupService.queryKtglReviewGroupPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<KtglReviewGroup>());
        } else {
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<KtglReviewGroup>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      e.printStackTrace();
      result.setRows(new ArrayList<KtglReviewGroup>());
      result.setTotal(0);
      LOGGER.error(
          "专家组管理信息 reviewTeacherGroupList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 专家组添加
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/addReviewTeacherGroupForward")
  @Token(save = true)
  public String addReviewTeacherGroupForward(ModelMap model, HttpServletRequest request) {
    try {
      Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
      if (loginType == 2) { // 老师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<Employee> employeeList = commonService.queryByAllEmployee(null);
        model.put("employeeList", employeeList);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "专家组信息 addReviewTeacherGroupForward [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return "teacherReviewGroup/addTeacherGroup";
  }

  /**
   * 验证专家组姓名是否重复
   * 
   * @param request
   * @param response
   * @param groupname
   * @param groupid
   * @return
   */

  @RequestMapping(value = "/valdateReviewTeacherGroup")
  public @ResponseBody Integer valdateReviewTeacherGroup(HttpServletRequest request,
      HttpServletResponse response, @RequestParam(value = "groupname") String groupname,
      @RequestParam(value = "groupid") Integer groupid) {
    response.setContentType("text/html;charset=utf-8");
    try {
      if (StringUtils.isNullValue(groupname)) {
        return -1;
      } else {
        KtglReviewGroup group = new KtglReviewGroup();
        group.setGroupid(groupid == -1 ? null : groupid);
        group.setGroupname(groupname);
        int num = ktglReviewGroupService.queryVerifyReviewTeacherGroup(group);
        if (num == 0) {
          return 0;
        } else {
          return 1;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "专家组信息 valdateReviewTeacherGroup [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return -2;
    }
  }

  /**
   * 添加专家组信息
   * 
   * @param model
   * @param request
   * @param ktglReviewGroup
   * @return
   */
  @RequestMapping(value = "/addReviewTeacherGroup")
  @Token(remove = true, path = "index")
  @SysLogger(description = "新增专家组信息", moduleName = "专家组管理", method = "新增")
  public String addReviewTeacherGroup(ModelMap model, HttpServletRequest request,
      KtglReviewGroup ktglReviewGroup) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 老师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String[] empids = request.getParameter("empids").split(",");
        ktglReviewGroup.setEmpids(empids);
        ktglReviewGroup.setMembernum(empids.length);
        int groupid = ktglReviewGroupService.addReviewGroup(ktglReviewGroup);
        String flag = request.getParameter("flag");
        if (groupid >= 1 && !StringUtils.isNullValue(flag) && "1".equals(flag)) { // 新增跳转到修改页面
          BaseController.setParameter("msg", "保存成功");
          return "redirect:modiftyReviewTeacherGroupForWard?groupid=" + groupid;
        } else if (groupid >= 1 && !StringUtils.isNullValue(flag) && "2".equals(flag)) { // 新增且继续新增
          BaseController.setParameter("msg", "保存成功");
          return "redirect:addReviewTeacherGroupForward";
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:index";
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "新增专家组信息 addReviewTeacherGroup [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 
   * 修改专家组信息跳转页面
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/modiftyReviewTeacherGroupForWard", method = RequestMethod.GET)
  public String modiftyReviewTeacherGroupForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "groupid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      KtglReviewGroup ktglReviewGroup = new KtglReviewGroup();
      List<Employee> employeeList = new ArrayList<Employee>();
      if (loginType == 2) { // 教师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<KtglReviewExpert> KtglReviewExpertList = new ArrayList<KtglReviewExpert>();
        if (id != null) {
          ktglReviewGroup = ktglReviewGroupService.queryReviewGroupByPK(id);
          if (ktglReviewGroup != null) {
            KtglReviewExpertList = ktglReviewGroupService.queryReviewExpertList(id);
          }
          employeeList = ktglReviewGroupService.queryReviewExpertByAllEmployee(id);
        }
        model.put("employeeList", employeeList);
        model.put("KtglReviewExpertList", KtglReviewExpertList);
        model.put("ktglReviewGroup", ktglReviewGroup);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "teacherReviewGroup/updateTeacherGroup";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      LOGGER.error("修改专家组信息信息 modiftyReviewTeacherGroupForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }

  }

  /**
   * 修改专家组信息
   * 
   * @param model
   * @param request
   * @param ktglReviewGroup
   * @return
   */
  @SysLogger(description = "修改专家组信息", moduleName = "专家组管理", method = "修改")
  @RequestMapping(value = "/modiftyReviewTeacherGroup", method = RequestMethod.POST)
  public String modiftyReviewTeacherGroup(ModelMap model, HttpServletRequest request,
      KtglReviewGroup ktglReviewGroup) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String[] empids = request.getParameter("empids").split(",");
        ktglReviewGroup.setMembernum(empids.length);
        ktglReviewGroup.setEmpids(empids);
        int num = ktglReviewGroupService.updateReviewGroupByPK(ktglReviewGroup);
        if (num >= 1) {
          BaseController.setParameter("msg", "保存成功");
        } else {
          BaseController.setParameter("msg", "保存失败");
        }
        return "redirect:modiftyReviewTeacherGroupForWard?groupid=" + ktglReviewGroup.getGroupid();
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:index";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "修改专家组信息 modiftyReviewTeacherGroup [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 删除专家组信息
   * 
   * @param model
   * @param request
   * @return
   */
  @SysLogger(description = "删除专家组信息", moduleName = "专家组管理", method = "删除")
  @RequestMapping(value = "/deleteReviewTeacherGroup", method = RequestMethod.POST)
  public String deleteReviewTeacherGroup(ModelMap model, HttpServletRequest request) {
    try {
      String[] idList = request.getParameter("idList").split(",");
      if (idList.length >= 1) {
        // 先根据是否有关联数据信息
        int num = ktglReviewGroupService.queryRealtionTeacherThesisCount(idList);
        if (num == 0) {
          num = ktglReviewGroupService.deleteAllReviewGroupByPK(idList);
          if (num >= 1) {
            BaseController.setParameter("msg", "删除成功");
          } else {
            BaseController.setParameter("msg", "删除失败");
          }
        } else {
          BaseController.setParameter("msg", "您选择的专家组信息已关联论文信息，删除失败");
        }
      }
      return "redirect:index";
    } catch (Exception e) {
      LOGGER.error(
          "删除专家组信息 deleteReviewTeacherGroup [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 专家论文评审
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/indexTeacherThesisReview")
  public String indexTeacherThesisReview(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "teacherReviewGroup/teacherThesisReview_audit_list";
  }

  /**
   * 
   * 专家论文评审列表
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/teacherThesisReviewList")
  @ResponseBody
  public ResponseResult teacherThesisReviewList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, TeacherThesis data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        data.setEmpid(userEmployee.getEmid());
        PaginationBean<TeacherThesis> paginationBean =
            ktglReviewGroupService.queryTeacherThesisReviewPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<TeacherThesis>());
        } else {
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<TeacherThesis>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<TeacherThesis>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "专家论文评审信息 teacherThesisReviewList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 
   * 专家论文评审修改页面跳转
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/teacherThesisReviewAuditForWard", method = RequestMethod.GET)
  public String teacherThesisReviewAuditForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "lwid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      cn.qidisoft.edu.hzjt.model.zyc.TeacherThesis teacherThesis =
          new cn.qidisoft.edu.hzjt.model.zyc.TeacherThesis();
      if (loginType == 2) { // 教师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<TeacherThesisAtt> teacherThesisAttList = null;
        KtglTeacherThesisReview ktglTeacherThesisReview = new KtglTeacherThesisReview();
        String zjid = request.getParameter("zjid");
        if (id != null) {
          teacherThesis.setLwid(id);
          // 论文信息
          teacherThesis = teacherThesisService.queryByPK(teacherThesis);
          if (teacherThesis != null) {
            TeacherThesisAtt att = new TeacherThesisAtt();
            att.setParentId(id);
            // 论文附件
            teacherThesisAttList = teacherThesisAttService.queryList(att);
            if (teacherThesisAttList == null) {
              teacherThesisAttList = new ArrayList<TeacherThesisAtt>();
            }
          }
          // 专家审批结果
          ktglTeacherThesisReview.setParentid(id);
          ktglTeacherThesisReview.setReviewerid(Integer.parseInt(zjid));
          ktglTeacherThesisReview =
              ktglReviewGroupService.queryTeacherThesisReview(ktglTeacherThesisReview);
          if (ktglTeacherThesisReview == null) {
            ktglTeacherThesisReview = new KtglTeacherThesisReview();
          }
        }
        ktglTeacherThesisReview.setParentid(id);
        ktglTeacherThesisReview.setReviewerid(userEmployee.getEmid());
        ktglTeacherThesisReview.setReviewername(userEmployee.getXm());
        ktglTeacherThesisReview.setPssj(DateUtil.formatDate2Str(new Date(), "yyyy-MM-dd HH:mm:ss"));
        model.put("teacherThesis", teacherThesis);
        model.put("teacherThesisAttList", teacherThesisAttList);
        model.put("ktglTeacherThesisReview", ktglTeacherThesisReview);
        model.put("currentDate", new Date());
        model.put("zjid", zjid);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "teacherReviewGroup/teacherThesisReview_audit";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexTeacherThesisReview";
      }
    } catch (Exception e) {
      LOGGER.error("修改专家论文评审 teacherThesisReviewAuditForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 专家论文信息评审
   * 
   * @param model
   * @param request
   * @param teacherThesis
   * @return
   */
  @SysLogger(description = "专家论文评审信息", moduleName = "专家评审", method = "审批")
  @RequestMapping(value = "/modiftyTeacherThesisReviewAudit", method = RequestMethod.POST)
  public String modiftyTeacherThesisReviewAudit(ModelMap model, HttpServletRequest request,
      KtglTeacherThesisReview ktglTeacherThesisReview) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      if (loginType == 2) { // 教师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        String lwid = request.getParameter("lwid");
        String zjid = request.getParameter("zjid");
        ktglTeacherThesisReview.setReviewtime(
            DateUtil.parseStr2Date(ktglTeacherThesisReview.getPssj(), "yyyy-MM-dd HH:mm:ss"));
        ktglTeacherThesisReview.setReviewerid(Integer.parseInt(zjid));
        if (!StringUtils.isNullValue(lwid)) {
          ktglTeacherThesisReview.setParentid(Integer.parseInt(lwid));
          int num = ktglReviewGroupService.updateTeacherThesisReview(ktglTeacherThesisReview);
          if (num >= 1) {
            BaseController.setParameter("msg", "保存成功");
          } else {
            BaseController.setParameter("msg", "保存失败");
          }
          return "redirect:teacherThesisReviewAuditForWard?lwid=" + lwid + "&zjid=" + zjid;
        } else {
          BaseController.setParameter("msg", "保存失败");
          return "redirect:indexTeacherThesisReview";
        }
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexTeacherThesisReview";
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("修改专家组信息 modiftyTeacherThesisReviewAudit [{}] error," + this.getClass().getName()
          + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 
   * 专家论文评审(管理端)
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/indexManagerTeacherThesisReview")
  public String indexManagerTeacherThesisReview(ModelMap model, HttpServletRequest request) {
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
    } catch (Exception e) {
      e.printStackTrace();
      return "error/error";
    }
    return "teacherReviewGroup/teacherManagerThesisReview_list";
  }

  /**
   * 
   * 专家论文评审列表(管理端)
   * 
   * @param model
   * @param request
   * @param pageSize
   * @param currentPage
   * @param data
   * @return
   */
  @RequestMapping(value = "/teacherManagerThesisReviewList")
  @ResponseBody
  public ResponseResult teacherManagerThesisReviewList(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "rows", required = false) String pageSize,
      @RequestParam(value = "page", required = false) String currentPage, TeacherThesis data) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    ResponseResult result = new ResponseResult();
    try {
      if (loginType == 2) { // 老师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage(currentPage, pageSize, request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        // data.setEmpid(userEmployee.getEmid());
        PaginationBean<TeacherThesis> paginationBean =
            ktglReviewGroupService.queryTeacherManagerThesisReviewPageList(data, page);
        if (paginationBean.getPageList().isEmpty()) {
          result.setRows(new ArrayList<TeacherThesis>());
        } else {
          for (TeacherThesis jky : paginationBean.getPageList()) {
            jky.setTjsj(DateUtil.formatDate2Str(jky.getCreatetime(), "yyyy-MM-dd HH:mm:ss"));
          }
          result.setRows(paginationBean.getPageList());
        }
        result.setTotal(paginationBean.getTotalRecords());
      } else {
        result.setRows(new ArrayList<TeacherThesis>());
        result.setTotal(0);
      }
      return result;
    } catch (Exception e) {
      result.setRows(new ArrayList<TeacherThesis>());
      result.setTotal(0);
      e.printStackTrace();
      LOGGER.error(
          "专家论文评审信息 teacherThesisReviewList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
    }
    return result;
  }

  /**
   * 
   * 专家论文评审结果(管理端)
   * 
   * @param model
   * @param request
   * @param id
   * @return
   */
  @RequestMapping(value = "/teacherManagerThesisReviewForWard", method = RequestMethod.GET)
  public String teacherManagerThesisReviewForWard(ModelMap model, HttpServletRequest request,
      @RequestParam(value = "lwid") Integer id) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      cn.qidisoft.edu.hzjt.model.zyc.TeacherThesis teacherThesis =
          new cn.qidisoft.edu.hzjt.model.zyc.TeacherThesis();
      if (loginType == 2) { // 教师
        // UserEmployee userEmployee =
        // (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        List<TeacherThesisAtt> teacherThesisAttList = null;
        KtglTeacherThesisReview ktglTeacherThesisReview = new KtglTeacherThesisReview();
        List<KtglTeacherThesisReview> ktglTeacherThesisReviewList =
            new ArrayList<KtglTeacherThesisReview>();
        if (id != null) {
          teacherThesis.setLwid(id);
          // 论文信息
          teacherThesis = teacherThesisService.queryByPK(teacherThesis);
          if (teacherThesis != null) {
            TeacherThesisAtt att = new TeacherThesisAtt();
            att.setParentId(id);
            // 论文附件
            teacherThesisAttList = teacherThesisAttService.queryList(att);
            if (teacherThesisAttList == null) {
              teacherThesisAttList = new ArrayList<TeacherThesisAtt>();
            }
          }
          // 专家审批结果
          ktglTeacherThesisReview.setParentid(id);
          ktglTeacherThesisReviewList =
              ktglReviewGroupService.queryTeacherThesisReviewList(ktglTeacherThesisReview);
          if (ktglTeacherThesisReview == null) {
            ktglTeacherThesisReviewList = new ArrayList<KtglTeacherThesisReview>();
          }
        }
        model.put("teacherThesis", teacherThesis);
        model.put("teacherThesisAttList", teacherThesisAttList);
        model.put("ktglTeacherThesisReviewList", ktglTeacherThesisReviewList);
        model.put("msg", BaseController.getParameter("msg"));
        BaseController.removeParameter("msg");
        return "teacherReviewGroup/teacherManagerThesisReview";
      } else {
        BaseController.setParameter("msg", "没权限访问该页面");
        return "redirect:indexManagerTeacherThesisReview";
      }
    } catch (Exception e) {
      LOGGER.error("查看专家论文评审 teacherManagerThesisReviewForWard [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
  }

  /**
   * 导出论文信息
   * 
   * @param model
   * @param request
   * @param data
   * @param response
   * @return
   */
  @RequestMapping(value = "/exportManagerTeacherThesisReview")
  public String exportManagerTeacherThesisReview(ModelMap model, HttpServletRequest request,
      TeacherThesis data, HttpServletResponse response) {
    Integer loginType = (Integer) request.getSession().getAttribute(Constant.LOGIN_USER_TYPE);
    try {
      String[][] title_name = {{"姓名", "职工号", "论文题目", "论文时间", "推荐结果", "获奖级别", "提交时间"}};
      String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
      String fileName = "论文信息";
      String[] remark = {""};
      List<Map<String, Object>> exportlist = new ArrayList<Map<String, Object>>();
      if (loginType == 2) { // 老师
        UserEmployee userEmployee =
            (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
        Page page = BaseController.getPage("0", "0", request, "createtime", "desc");
        data.setOrderField((String) request.getAttribute("orderField"));
        data.setOrderFlag((String) request.getAttribute("orderFlag"));
        List<TeacherThesis> list =
            ktglReviewGroupService.exportTeacherManagerThesisReviewList(data);
        if (!list.isEmpty()) {
          for (TeacherThesis res : list) {
            Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("xm", res.getEmpname());
            map.put("zgh", res.getZgh());
            map.put("subject", res.getSubject());
            map.put("lwsj", res.getLwsj());
            map.put("tjjg", res.getTjjg());
            map.put("hjjb", res.getHjjb());
            map.put("createtime",
                DateUtil.formatDate2Str(res.getCreatetime(), "yyyy-MM-dd hh:mm:ss"));
            exportlist.add(map);
          }
        }
      }
      HSSFWorkbook wb =
          ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, exportlist);
      response.reset();
      response.setContentType("application/vnd.ms-excel;charset=utf-8");
      response.setHeader("Content-Disposition",
          "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
      response.setDateHeader("Expires", 0);
      ServletOutputStream os = response.getOutputStream();
      wb.write(os);
      os.flush();
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("导出论文信息（管理端） exportManagerTeacherThesisReview [{}] error,"
          + this.getClass().getName() + "=[{}]", this.getClass().getName(), e.getMessage());
      model.addAttribute(Constant.EXPTION_MSG_KEY, e);
      return "error/error";
    }
    return null;
  }


}
